package GUI.List;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;

import javax.swing.*;

import GUI.TabPanel.TabPanel;

public class NewList extends JScrollPane {

	private static final long serialVersionUID = 1L;
	private JList<String> List = null;
	private DefaultListModel<String> Model = null;

	private TabPanel TabPanels;

	public void addHost(ArrayList<String> hosts) {
		if (hosts != null) {
			Model.clear();
			for(String tmp : hosts) {
				Model.addElement(tmp);
			}
		}
	}

	private void initModel() {

		List = new JList<String>();
		Model = new DefaultListModel<String>();

	}

	private void initList() {
		List.setModel(Model);
		List.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				if (e.getClickCount() == 2) {
					TwoClick(List.getSelectedValue());
				}
			}
		});
	}

	private void TwoClick(Object SelectObject) {
		this.TabPanels.Refresh(SelectObject);
	}

	public void setPanel(TabPanel TabPanels) {
		this.TabPanels = TabPanels;
	}

	public NewList() {
		initModel();
		initList();
		this.setViewportView(List);
	}

}
